package com.summer.data.jql.concept;

import com.summer.data.Jsql;
import com.summer.data.dialect.Dialect;
import com.summer.data.exception.BaseException;
import com.summer.data.jql.Context;

/**
 * @author 345480567@qq.com
 */

public class NativeValue<T> implements Field {

    protected T val;

    public static NativeValue<Integer> use(Integer val) {
        return new NativeValue(val);
    }

    public static NativeValue<String> use(String val) {
        return new NativeValue(val);
    }

    public NativeValue(T val) {
        this.val = val;
    }

    @Override
    public Jsql toGroupSql(Context ctx, Dialect dialect) {
        throw new BaseException("Const<T> 不支持 Group 操作。");
    }

    @Override
    public Jsql toFieldSql(Context ctx, Dialect dialect) {
        if (val instanceof String) {
            return Jsql.format("'%s'", val);
        } else {
            return Jsql.format("%s", val);
        }
    }
}
